package com.markus.code.exam.laohujituan;

import java.util.List;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/6 16:38
 * todo:
 */
public class Main {
    /**
     *
     * @param N int整型
     * @return int整型
     */
    public int primePalindrome (int N) {
        // write code here
        int min = -1;
        for (int i=N;;i++){
            String s = String.valueOf(i);
            if (isPrime(i) && isPar(s)){
                min = i;
                break;
            }
        }
        return min;
    }
    private boolean isPar(String s){
        char []ch = s.toCharArray();
        for (int i=0;i<ch.length/2;i++){
            if (ch[i] != ch[ch.length-1-i]){
                return false;
            }
        }
        return true;
    }
    private boolean isPrime(int n){
        boolean flag = true;
        for (int i=2;i<=(int)Math.sqrt(n);i++){
            if (n % i == 0){
                flag = false;
                break;
            }
        }
        return flag;
    }

    public static void main(String[] args) {
        Main demo = new Main();
        System.out.println(demo.primePalindrome(6));
    }
}
